<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>四川新华扬科技有限公司－雷达权限管理</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- <link href="../../AceAdmin/assets/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="../../AceAdmin/assets/css/font-awesome.min.css" />
<link rel="stylesheet" href="../../AceAdmin/assets/css/ui.jqgrid.css" />
<link rel="stylesheet" href="../../AceAdmin/assets/css/chosen.css" />
<link rel="stylesheet" href="../../AceAdmin/assets/css/ace.min.css" /> -->
<link rel="stylesheet" href="../../css/icon/radarico/iconfont.css"/>
<link rel="stylesheet" type="text/css" href="../../plug/paging/css/zxf_page.css">
<link rel="stylesheet" type="text/css" href="../../plug/paging/css/yeIcon/iconfont.css">
<link rel="stylesheet" type="text/css" href="../../css/company/radar.css">

<script src="../../AceAdmin/assets/js/ace-extra.min.js"></script>


<script src="../../js/common.js" type="application/javascript"></script>

</head>
<body>
<div class="radar">
  <h3>雷达管理权限</h3>
  <div class="radarTop">
    <div class="radarDep"><span id="section"></span>(<span id="sectionNum"></span>人)</div>
    <div class="choice">选择部门</div>
    <div class="er">
      <div class="erK"><i class="iconfont icon-erweima_o" id="er"></i></div>
      <div class="erKw">企业二维码</div>
    </div>
    <div class="radarMem">
      <text>已开通/可开通 ( <span class="cardOne">0</span>/<span class="cardAll">0</span> )</text>
      <!-- <text class="memberEnlarge">申请扩容</text> -->
    </div>
  </div>
  <div class="radarEr">
    <img src="" class="radarErImg">
    <p class="p1 infoAjax">刷新二维码</p>
    <p class="p2">微信扫码关注企业号</p>
  </div>
  <div class="searchAll">
    <div class="search">
      <div class="kuan"><div class="searchL"><!-- <i class="iconfont icon-sousuo_o ca"></i> --><input type="text" name="" placeholder="输入员工姓名搜索" class="souName"></div></div>
      <div class="searchR"><i class="iconfont icon-sousuo_o ca"></i></div>
    </div>
    <div class="opens">批量开通</div>
  </div>
  <div class="tableAll">
    <div class="table">
      <div class="table2excel">
      <table class="table table-striped table-bordered table-hover">
        <thead>
          <tr>
            <th class="th3">头像</th>
            <th class="th4">姓名</th>
            <th class="th5">职位</th>
            <th class="th6">部门</th>
            <th class="th7">手机</th>
            <th class="th8">CRM和名片</th>
            <th class="th9">人事</th>
            <th class="th10">操作</th>
          </tr>
        </thead>
        <tbody id="tbdoy"></tbody>
      </table>
      </div>

      <div class="tableBotts">
        <div class="commons">共<text class="comNum"></text>页</div>
          <div class="zxf_pagediv"></div>
        <!-- <div class="commons">共<text class="comNum"></text>页</div>
        <div class="tableBotL">
         <nav aria-label="Page navigation">
          <ul class="pagination">
            <li class="last1">
              <a href="#" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
              </a>
            </li>
            <li><a href="#" class="xiazA">1</a></li>
            <li class="nex1">
              <a href="#" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
              </a>
            </li>
          </ul>
        </nav>
        </div>
        <div class="tableBotR">
          跳转到：
          <select id="pid" onchange="gradeChange()"></select>
        </div> -->
      </div>
    </div>
  </div>
<div class='dredge'>
  <div class="dredgeZ">
    <div class='dredgeT'>批量开通CRM和名片</div>
    <div class='dredgeBottom'>
      <div class='dredgeL'>
        <div class='dredgeLT'>
          <input type="checkbox" name="dredgeQ" class="dredgeQ">
          未开通成员
        </div>
        <div class='dredgeLC'>
        </div>
        <div class='dredgeLB'>
        </div>
      </div>
      <div class='dredgeC'>
        <div class="left"><i class='iconfont icon-jiantou_liebiaoxiangzuo_o' id='left'></i></div>
        <div class="right"><i class='iconfont icon-jiantou_liebiaoxiangyou_o' id='right'></i></div>
      </div>
      <div class='dredgeR'>
        <div class='dredgeRT'>
          <input type="checkbox" name="dredgeS" class="dredgeS">
          需开通成员
        </div>
        <div class='dredgeRC'>
          
        </div>
        <div class='dredgeRB'>
          清空
        </div>
      </div>
    </div>
    <div class="dredgeEnd">
      <div class="dredgeBtn">确定</div>
    </div>
    <div class="dredgeDel"><i class='iconfont icon-guanbi_o' id='tuandel'></i></div>
  </div>
  </div>
</div>
<!-- 部门弹窗 -->
<!-- <div class="tanz">
  <div class="tuanOne">
    <div class="tuanTop">选择部门</div>
    <div class="tuanbottom"></div>
    <div class="tuanBtn">确定</div>
    <div class="tuanDel"><i class='iconfont icon-guanbi_o' id='tuandel1'></i></div>
  </div>
</div> -->
<!-- 个人二维码 -->
<!-- <div class="erwz">
  <div class="erwOne">
    <div class="erwTop"></div>
    <div class="erwbottom"></div>
    <div class="erwBtn">刷新</div>
    <div class="erwDel"><i class='iconfont icon-guanbi_o' id='erwdel1'></i></div>
  </div>
</div> -->
<div id="loads" style="display:block;position: fixed;top: 0;left: 0;background:rgba(0,0,0,0);width:100%;height: 100%;vertical-align: middle;z-index:99999;">
    <div style="width:100%;height:100%;display:flex;vertical-align: middle;">
        <div style="width:100px;height:140px;margin: auto;">
            <img src="../../imgs/load.gif" alt="" class="load1Img" style="width:100%;height:auto;border-radius:5px;background: rgba(0,0,0,0.5);" />
            <div class="loadFont" style='width:100%;text-align: center;display: block;color:#fff;font-size: 20px;'></div>
        </div>
    </div>
</div>
<div id="radarNews"></div>
<div id="radarUpdatas" class="radarUpdatas"></div>
</body>
<script type="text/javascript">
   window.jQuery || document.write("<script src='../../AceAdmin/assets/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
</script>
<script type="text/javascript">
    if("ontouchend" in document) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script>
<script src="../../js/wenjian.js"></script>
<script src="../../plug/paging/js/zxf_page.js" type="text/javascript"></script>
<!-- <script type="text/javascript" src="../../js/company/radar.js"></script> -->
<script type="text/javascript">
  // console.log("111111111")
    document.querySelector(".radar").style.height =  window.innerHeight +"px"
    document.querySelector(".radar").style.overflowY =  "auto"
    for(var i=1; i <= $(".comNum").html();i++){
      var sel = $("<option value='"+i+"'>"+i+"</option>")
      $(sel).appendTo("#pid")
    }
    var conten = $(".radar").height();
  var staffAlls = [];//所有成员
  //首次进入渲染成员
  function staffAjax(){
    $("#loads").css("display","block")
    $.ajax({
      url: window.minitest.url + "member/list",
      type:"GET",
      beforeSend: function (request) {
          request.setRequestHeader('token', window.base.getLocalStorage('token'));
      },
      success:function(res){
        $("#loads").css("display","none")
        $("#sectionNum").html(res.length)
        console.log(res)
        staffAlls = res
        var rasleng = Math.ceil(res.length / 10);
        // console.log(rasleng);
        $(".comNum").html(rasleng)
        // selnum(rasleng);
        fenye(rasleng)
        strAll(staffAlls,1)
      },
      error:function(res){
        $("#loads").css("display","none")
        tokenDetection(res)
      }
    });
  }
  //获取企业二维码
  infoAjax()
  function infoAjax(){
    
    $.ajax({
      url: window.minitest.url + "thirdapp/info",
      type:"GET",
      contentType: "application/json",
      dataType:"json",
      beforeSend: function (request) {
          request.setRequestHeader('token', window.base.getLocalStorage('token'));
      },
      success:function(res){
        $("#loads").css("display","none")
        // console.log(res)
        document.querySelector(".radarErImg").src = res.work.corp_wxqrcode
      },
      error:function(res){
        $("#loads").css("display","none")
        console.log(res)
        // tokenDetection(res)
      }
    });
  }
  $(".infoAjax").click(function(){
    $("#loads").css("display","block")
    infoAjax()
  })
  staffAjax();
  //开通名片数
  function dredgesAjax(){
    $.ajax({
      url: window.minitest.url + "thirdapp/workuser",
      type:"GET",
      beforeSend: function (request) {
          request.setRequestHeader('token', window.base.getLocalStorage('token'));
      },
      success:function(res){
        var ress = JSON.parse(res)
        if(ress.cardNum){
          $(".cardAll").html(ress.cardNum)
        }
        if(ress.useNum){
          $(".cardOne").html(ress.useNum)
        }
        
        // console.log(JSON.parse(res))
      },
      error:function(res){
        console.log(res)
      }
    });
  }
  dredgesAjax();
  //开通名片
  function dredgeAjax(types,infos,wu_id,e,toggle1,panNum){
    console.log(types,infos,wu_id)
    $("#loads").css("display","block")
    //console.log(JSON.stringify({type:types,info:infos,wu_id:wu_id}))
    $.ajax({
        url: window.minitest.url + "member/authorize",
        type:"POST",
        contentType: "application/json",
        dataType:"json",
        beforeSend: function (request) {
          request.setRequestHeader('token', window.base.getLocalStorage('token'));
        },
        data:JSON.stringify({
          type:types,
          info:infos,
          wu_id:wu_id
        }),
        
        success:function(res){
          console.log(res)
          $("#loads").css("display","none")
          if(res.code == 201){
            if(types == "on"){
              alert("开通名片成功")
              if(panNum == 1){
                if($(toggle1).attr("class") == "toggle toggle1 toggle--off"){
                  $(toggle1).css("border","2px solid #4f81d4")
                }
                if($(toggle1).attr("class") == "toggle toggle1 toggle--on"){
                  $(toggle1).css("border","2px solid #ccc")
                  $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].classList.remove("toggle--on");
                  $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].classList.add("toggle--off");
                  $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].style.border="2px solid #ccc"
                }
                
              }
              if(panNum == 2){
                $(toggle1).parent().parent()[0].childNodes[5].childNodes[0].classList.remove("toggle--off");
                $(toggle1).parent().parent()[0].childNodes[5].childNodes[0].classList.add("toggle--on");
                $(toggle1).parent().parent()[0].childNodes[5].childNodes[0].style.border="2px solid #4f81d4"
                if($(toggle1).attr("class") == "toggle toggle2 toggle--off"){
                  $(toggle1).css("border","2px solid #4f81d4")
                }
                if($(toggle1).attr("class") == "toggle toggle2 toggle--on"){

                  $(toggle1).css("border","2px solid #ccc")
                }
                // console.log($(toggle).attr("class"))
                
              }
              // $(toggle1).css("border","2px solid #4f81d4")
              //$(toggle1).css("border","2px solid #ccc")
              // $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].classList.remove("toggle--on");
              // $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].classList.add("toggle--off");
              //$(toggle1).parent().parent()[0].childNodes[6].childNodes[0].style.border="2px solid #ccc"
              var numUser = parseInt($(".cardOne").html())
              console.log(numUser)
              var numUser2 = numUser+1
              console.log(numUser2)

              $(".cardOne").html(numUser2)

            }
            if(types == "off"){
              alert("关闭名片成功")
              if(panNum == 1){
                if($(toggle1).attr("class") == "toggle toggle1 toggle--off"){
                  $(toggle1).css("border","2px solid #4f81d4")
                }
                if($(toggle1).attr("class") == "toggle toggle1 toggle--on"){
                  $(toggle1).css("border","2px solid #ccc")
                  $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].classList.remove("toggle--on");
                  $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].classList.add("toggle--off");
                  $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].style.border="2px solid #ccc"
                }
                
              }
              if(panNum == 2){
                $(toggle1).parent().parent()[0].childNodes[5].childNodes[0].classList.remove("toggle--off");
                $(toggle1).parent().parent()[0].childNodes[5].childNodes[0].classList.add("toggle--on");
                $(toggle1).parent().parent()[0].childNodes[5].childNodes[0].style.border="2px solid #4f81d4"
                if($(toggle1).attr("class") == "toggle toggle2 toggle--off"){
                  $(toggle1).css("border","2px solid #4f81d4")
                }
                if($(toggle1).attr("class") == "toggle toggle2 toggle--on"){

                  $(toggle1).css("border","2px solid #ccc")
                }
                // console.log($(toggle).attr("class"))
              
              }
              //$(toggle1).css("border","2px solid #4f81d4")
              // $(toggle1).parent().parent()[0].childNodes[5].childNodes[0].classList.remove("toggle--off");
              // $(toggle1).parent().parent()[0].childNodes[5].childNodes[0].classList.add("toggle--on");
              //$(toggle1).parent().parent()[0].childNodes[5].childNodes[0].style.border="2px solid #4f81d4"
              if(infos == "ai"){
                var numUser = parseInt($(".cardOne").html())
                // console.log(numUser)
                var numUser2 = numUser-1
                // console.log(numUser2)
                $(".cardOne").html(numUser2)
              }
            }
            e.preventDefault();
            $(toggle1).toggleClass('toggle--on')
                   .toggleClass('toggle--off')
                   .addClass('toggle--moving');
            
            setTimeout(function() {
              $(toggle1).removeClass('toggle--moving');
            }, 200)
          }else{
            alert(res.msg)
          }
        },
        error:function(res){
          $("#loads").css("display","none")
          tokenDetection(res)
        }
    })
  }
  // //获取用户二维码
  // function acquireAjax(id){
  //   console.log("ujjjjjjjjjjuihj")
  //   window.parent.$(".radarImg").attr("src",'')
  //   $.ajax({
  //     url: window.minitest.url + "member/qrcode/" + id,
  //     type:"GET",
  //     contentType: "application/json",
  //     dataType:"json",
  //     beforeSend: function (request) {
  //         request.setRequestHeader('token', window.base.getLocalStorage('token'));
  //     },
  //     success:function(res){
  //       console.log(res)
  //       //if(res.error_code == 999){
  //       //  alert("该成员未开通名片")
  //       //}
  //       //if(res.error_code == 0){
  //       //  window.parent.$(".radarImg").attr("src",res.url)
  //       //}
  //       //if(res.error_code == 500){
  //       //  alert("获取二维码失败，请刷新页面重试")
  //       //}
  //     },
  //     error:function(res){
  //       tokenDetection(res)
  //     }
  //   });
  // }
  //创建tr
  var k=0;
  function strAll(starArr,inde){
    var tr = document.querySelectorAll(".tr")
        // console.log(tr)
        Array.from(tr).forEach(function(c,d){
          c.remove()
        })
        if(starArr.length > 0){
          $.each(starArr, function(index, el) {
          if(index < inde*10 && index >= inde*10 - 10){
            var toggles1 = "toggle--off"
            var toggles2 = "toggle--off"

            if(el.ai_power == "on"){
              toggles1 = "toggle--on"
            }
            if(el.boss_power == "on"){
              toggles2 = "toggle--on"
            }
            //部门格渲染
            var parameter = el.departments
             var text
             if(parameter.length > 0){
               parameter.forEach(function(a,b){
                  if(text){
                    text = text + "<text did='"+a.d_id+"'>、"+a.name+"</text>";
                  }else{
                    text = "<text did='"+a.d_id+"'>"+a.name+"</text>";
                  }
               })
             }else{
              text = ''
             }
            var staffsAdd = $("<tr class='tr'><td class='td1'><img src='"+el.userimg.url+"' class='tableImage'></td><td class='td2'>"+el.name+"</td><td class='td3'>"+el.position+"</td><td class='td4' ><div class='td6div' id='dep"+index+"' uid='"+el.user_id+"'>"+text+"</div></td><td class='td5'>"+el.bind_phone+"</td><td class='td6'><span class='toggle toggle1 "+toggles1+"' did='"+el.id+"' sid='ai'></span></td><td class='td7'><span class='toggle toggle2 "+toggles2+"' did='"+el.id+"' sid='boss'></span></td><td class='td8' did='"+el.id+"'>二维码</td></tr>")
            $(staffsAdd).appendTo("#tbdoy");
            // var idName='dep'+index

            // for(var key in el.department){
            //   k++;
            //   if(el.department.length>1){

            //     var text = $("<text did='"+key+"'>"+el.department[key]+"、</text>");
            //   }else{
            //     var text = $("<text did='"+key+"'>"+el.department[key]+"</text>");
            //   }
            //   $(text).appendTo("#"+idName)
            // }
          }
      })
      }else{
        var staffsAdd = $("<tr class='tr'><td class='td1' colspan='8'>暂无数据</td></tr>")
      $(staffsAdd).appendTo("#tbdoy");
      }
    
      var td8 = document.querySelectorAll(".td8")
      // console.log(td8)
      erwei(td8);
    
    //企业微信二维码
    $(".er").mouseenter(function(){
      // console.log(111111111111)
      $(".radarEr").mouseenter(function(){
        // console.log(33333333)
        $(".radarEr").css("display","block")
      })
      $(".radarEr").mouseleave(function(){
        // console.log(44444444)
        $(".radarEr").css("display","none")
      })
      $(".radarEr").css("display","block")
      $(".er").mouseleave(function(){
        $(".radarEr").css("display","none")
      })
    })
    //按钮
    $('.toggle1').click(function(e) {
      var toggle1 = this;
      var xians;
      var wu_id = $(toggle1).attr("did")
      var info = $(toggle1).attr("sid")
      var types;
      if($(toggle1).attr("class") == "toggle toggle1 toggle--off"){
        xians="确定开通CRM和名片？"
        types = "on"
      }
      if($(toggle1).attr("class") == "toggle toggle1 toggle--on"){
        xians="确定关闭CRM和名片？"
        types = "off"
      }
      bootbox.dialog({
        message: "<div class='row'><div class='department'>"+xians+"</div></div>",
        buttons:{
          "取消":{
            "className": "btn-sm btn-danger",
            "callback":function(){ }
          },
          "确定":{
            "className": "btn-sm btn-success",
            "callback":function(){ 
                dredgeAjax(types,info,wu_id,e,toggle1,1)
                // if($(toggle1).attr("class") == "toggle toggle1 toggle--off"){
                //   $(toggle1).css("border","2px solid #4f81d4")
                // }
                // if($(toggle1).attr("class") == "toggle toggle1 toggle--on"){
                //   $(toggle1).css("border","2px solid #ccc")
                //   $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].classList.remove("toggle--on");
                //   $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].classList.add("toggle--off");
                //   $(toggle1).parent().parent()[0].childNodes[6].childNodes[0].style.border="2px solid #ccc"
                // }
                // e.preventDefault();
                // $(toggle1).toggleClass('toggle--on')
                //        .toggleClass('toggle--off')
                //        .addClass('toggle--moving');
                
                // setTimeout(function() {
                //   $(toggle1).removeClass('toggle--moving');
                // }, 200)
            }
          }
        }
      })
      $(".modal-content").css("width","300px")
      $(".modal-content").css("margin","auto")
      $(".modal-content").css("margin-top","20%")
      $(".modal-footer").css("margin","0")
      $(".modal-footer").css("background","#fff")
      $(".modal-body").css("padding","20px 20px 0 20px")
      // console.log($(toggle1).attr("class"))
     
    });
    $('.toggle2').click(function(e) {
      var toggle = this;
      var xians;
      var wu_id1 = $(toggle).attr("did")
      var info1 = $(toggle).attr("sid")
      var types1;

      // console.log($(toggle).attr("class"))
      if($(toggle).attr("class") == "toggle toggle2 toggle--off"){
        // $(toggle).css("border","2px solid #4f81d4")
        xians="确定开通人事？"
        types1 = "on"
      // console.log(xians)

      }
      if($(toggle).attr("class") == "toggle toggle2 toggle--on"){
        xians="确定关闭人事？"
        types1 = "off"
        // $(toggle).css("border","2px solid #ccc")
      }
      // console.log(xians)
      bootbox.dialog({
        message: "<div class='row'><div class='department'>"+xians+"</div></div>",
        buttons:{
          "取消":{
            "className": "btn-sm btn-danger",
            "callback":function(){ }
          },
          "确定":{
            "className": "btn-sm btn-success",
            "callback":function(){ 
                // console.log(xians)
                dredgeAjax(types1,info1,wu_id1,e,toggle,2)
                // $(toggle).parent().parent()[0].childNodes[5].childNodes[0].classList.remove("toggle--off");
                // $(toggle).parent().parent()[0].childNodes[5].childNodes[0].classList.add("toggle--on");
                // $(toggle).parent().parent()[0].childNodes[5].childNodes[0].style.border="2px solid #4f81d4"
                // if($(toggle).attr("class") == "toggle toggle2 toggle--off"){
                //   $(toggle).css("border","2px solid #4f81d4")
                // }
                // if($(toggle).attr("class") == "toggle toggle2 toggle--on"){

                //   $(toggle).css("border","2px solid #ccc")
                // }
                // // console.log($(toggle).attr("class"))
                // e.preventDefault();
                // $(toggle).toggleClass('toggle--on')
                //        .toggleClass('toggle--off')
                //        .addClass('toggle--moving');
                
                // setTimeout(function() {
                //   $(toggle).removeClass('toggle--moving');
                // }, 200)
            }
          }
        }
      })
      $(".modal-content").css("width","300px")
      $(".modal-content").css("margin","auto")
      $(".modal-content").css("margin-top","20%")
      $(".modal-footer").css("margin","0")
      $(".modal-footer").css("background","#fff")
      $(".modal-body").css("padding","20px 20px 0 20px")
      console.log($(toggle).parent().parent()[0].childNodes[5].childNodes[0])
     
    });
            // var trZ = document.querySelectorAll("tr");
            // particulars(trZ)
  }
  //分页
  function fenye(num){
    $(".comNum").html(num)
    $(".zxf_pagediv").createPage({
      pageNum: num,
      current: 1,
      backfun: function(e) {
        // var tr = document.querySelectorAll(".tr")
        // // console.log(tr)
        // Array.from(tr).forEach(function(c,d){
        //   c.remove()
        // })
        strAll(staffAlls,e.current)
        console.log(e.current)
        console.log(e);//回调
      }
    });
  }

     //搜索
    $(".searchR").click(function(){
      $("#loads").css("display","block")
      var souArr = []
      var souName = $.trim($('.souName').val());
      var td4Arr = [];
      var td4 = document.querySelectorAll(".td4")
      // var tr = document.querySelectorAll(".tr")
      //  Array.from(tr).forEach(function(c,d){
      //   c.remove()
      // })
      Array.from(staffAlls).forEach(function(a,b){
        var str = a.name
        if(str.indexOf(souName) == 0){
          souArr.push(a)
        }
      })
      strAll(souArr,1)
      $("#loads").css("display","none")
    })
    // var listArrs = []
    //获取开通未开通成员名单
    function listAjax(){
      $("#loads").css("display","block")
      $.ajax({
        url: window.minitest.url + "member/status",
        type:"GET",
        contentType: "application/json",
        dataType:"json",
        beforeSend: function (request) {
            request.setRequestHeader('token', window.base.getLocalStorage('token'));
        },
        success:function(res){
          console.log(res)
          // if(res.on.length>0){

          //   $.each(res.on, function(index, el) {
          //     console.log(index,el.name,el.id)
          //     var divOn = $("<div class='dredgeOne' userId='"+el.id+"'><input type='checkbox' name='dredgeO' class='dredgeO' did='"+el.id+"' checked='checked'>"+el.name+"</div>")
          //     $(divOn).appendTo(".dredgeRC");
          //     // var obj = {
          //     //   userid:el.id,
          //     //   name:el.name
          //     // }
          //     // listArrs.push(obj)
          //     // cancel()
          //   })
          // }
          if(res.off.length>0){
            $.each(res.off, function(index, el) {
              console.log(index,el.name,el.id)
              var divOn = $("<div class='dredgeOne' userId='"+el.id+"'><input type='checkbox' name='dredgeO' class='dredgeO' did='"+el.id+"'>"+el.name+"</div>")
              $(divOn).appendTo(window.parent.$(".popupCenter"));
            })
          }
          // console.log(listArrs)
          $("#loads").css("display","none")
          
        },
        error:function(res){
          $("#loads").css("display","none")
          tokenDetection(res)
        }
      });
    }
    //批量开通
    function onAjax(arr){
      $("#loads").css("display","block")
      $.ajax({
          url: window.minitest.url + "member/batch/on",
          type:"POST",
          contentType: "application/json",
          dataType:"json",
          beforeSend: function (request) {
            request.setRequestHeader('token', window.base.getLocalStorage('token'));
          },
          data:JSON.stringify({
              type:"on",
              info:"ai",
              list:arr
          }),
        success:function(res){
          $("#loads").css("display","none")
          //console.log(res)
          if(res.code == 201){
            alert("开通成功")
          }else{
            alert("开通失败，请刷新页面重试")
          }
          $(".dredge").css("display","none")
          window.location.reload();
          
        },
        error:function(res){
          $("#loads").css("display","none")
          tokenDetection(res)
        }
      });
    }
    //批量关闭
    function offAjax(arr){
      $("#loads").css("display","block")
      $.ajax({
          url: window.minitest.url + "member/batch/on",
          type:"POST",
          contentType: "application/json",
          dataType:"json",
          beforeSend: function (request) {
            request.setRequestHeader('token', window.base.getLocalStorage('token'));
          },
          data:JSON.stringify({
              type:"off",
              info:"ai",
              list:arr
          }),
        success:function(res){
          $("#loads").css("display","none")
          console.log(res)
          
        },
        error:function(res){
          $("#loads").css("display","none")
          tokenDetection(res)
        }
      });
    }
  //批量开通按钮
  $(".opens").click(function(){
    offs = true
    var divs = "<div class='popup'><div class='popupTitle'>批量开通CRM和名片</div><div class='popupCenter'></div><div class='popupBottom'><div class='popupYes' onclick='radarOrganization()'>确定</div></div><div class='padlock' onclick='padlocks()'><i class='iconfont icon-guanbi' id='del' style='line-height:30px;'></div></div>"
    $(divs).appendTo(window.parent.$("#messagediv"));
    window.parent.$("#messagedivs").css("display","block")
    // $(".dredge").css("display","block")
    listAjax()
    // bootbox.dialog({
    //   message: "<div class='dredge'><div class='dredgeT'>批量开通CRM和名片</div><div class='dredgeBottom'><div class='dredgeL'><div class='dredgeLT'><input</div><div class='dredgeLC'></div><div class='dredgeLB'></div></div><div class='dredgeC'></div><div class='dredgeR'></div></div></div>",
    //   buttons:{
    //     "确定":{
    //       "className": "btn-sm btn-success",
    //       "callback":function(){}
    //     }
    //   }
    // })
    // // $(".modal-content").css("width","300px")
    // $(".modal-content").css("margin","auto")
    // // $(".modal-content").css("margin-top","20%")
    // $(".modal-footer").css("margin","0")
    // $(".modal-footer").css("background","#fff")
    // $(".modal-body").css("padding","20px 20px 0 20px")
    
  })
  var offs = true
  var titles = $('#radarUpdatas');//the element I want to monitor
  titles.bind('DOMNodeInserted', function(e) {
      var dispenseSon = document.querySelectorAll('.dispenseSonss');
      // console.log(dispenseSon)
      var dispenseSonArr = []
      Array.from(dispenseSon).forEach(function(el,index){
        dispenseSonArr.push(el.getAttribute("sid"))
      })
      
      if(dispenseSonArr.length == dispenseSon.length){
        if(offs){
          console.log(dispenseSonArr)
          if(dispenseSonArr.length<1){
            alert("请选择需要开通的成员")
            return false
          }else{
            onAjax(dispenseSonArr)
          }
          offs = false
        }
        
      }
      
      // var div_id = dispenseSon.getAttribute('sid');
      // var div_name = dispenseSon.getAttribute('cid');
      // $("#section").html(div_name)
      // routAjax(div_id)
      // console.log(dispenseSon)

      // console.log(dispenseSon.getAttribute('sid'))
      // console.log(dispenseSon.getAttribute('cid'))

  });

  //全部选中
  var tblP=true;
  var pan = 0;
  $(".dredgeQ").click(function(){
    var tableBott = document.querySelectorAll('.dredgeO');
    pan++;
    Array.from(tableBott).forEach(function(a,b){
      if(pan % 2 == 1){
        Arrays=[];
        // Arrays=arrs
        var tableBo = document.querySelectorAll('.dredgeO');
          Array.from(tableBo).forEach(function(a,b){
            var obj={
              userid:a.parentNode.getAttribute("userid"),
              name:a.parentNode.childNodes[1].textContent
            }
            Arrays.push(obj)
          })
        a.checked = true;
      }else{
        Arrays=[];
        a.checked = false;
      }
    })
    quanx()
    console.log(Arrays)
    dredge()
  })
    var Arrays = [];//选中的成员
    var arrs = [{userid:1,name:"张三"},{userid:2,name:"李四"},{userid:3,name:"王五"}]
    //选中与取消选中成员
    quanx()
  function quanx(){
    var tableBo = document.querySelectorAll('.dredgeO');
    Array.from(tableBo).forEach(function(a,b){
      a.onclick=function(){
        console.log(a.parentNode.childNodes[1].textContent)
        if(a.checked == true){
          if(Arrays.length<1){
            var obj={
              userid:a.parentNode.getAttribute("userid"),
              name:a.parentNode.childNodes[1].textContent
            }
            Arrays.push(obj)
          }
          var ks = true;
          var objs={}
          if(Arrays.length>=1){
            Arrays.forEach(function(e,f){
              if(e.userid == a.parentNode.getAttribute("userid")){
                ks = true;
              }else{
                ks = false;
              }
            })
            if(!ks){
                objs={
                  userid:a.parentNode.getAttribute("userid"),
                  name:a.parentNode.childNodes[1].textContent
                }
                Arrays.push(objs)

            }
          }
        }
        if(a.checked == false){
          Arrays.forEach(function(x,y){
            if(x.userid == a.parentNode.getAttribute("userid")){
              Arrays.splice(Arrays.indexOf(x,0),1)
            }
          })
        }
        console.log(Arrays)
      dredge()
      }
    })
  }
  // quanx()

    //选择左边员工
  var ArrOs=[]
  function dredge(){
    var yes = 0;
    var no = 0;
    var tableBott = document.querySelectorAll('.dredgeO');
     Array.from(tableBott).forEach(function(a,b){
      if(a.checked == true){
        yes++;
      }
    })
     if(yes>0){
      $(".right").css("background","#4f81d4")
      $(".right").attr("background","#4f81d4")
    }
     if(yes<1){
      $(".right").css("background","#fff")
      $(".right").attr("background","#fff")
     }

     //删除左边并在右边添加员工
    $(".right").click(function(){
      if($(".right").attr("background")=="#4f81d4"){
        var tableBott = document.querySelectorAll('.dredgeO');
        Array.from(tableBott).forEach(function(c,d){
          if(c.checked == true){
            c.parentNode.remove()
          }
        })
        Arrays.forEach(function(dom,index){
          var newN = $("<div class='dredgeOnes' userId='"+dom.userid+"'><input type='checkbox' name='dredgeOs' class='dredgeOs' did='"+dom.userid+"' checked='checked'>"+dom.name+"</div>")
          $(newN).appendTo(".dredgeRC")
          document.querySelector(".dredgeS").checked = true;
          $(".left").css("background","#4f81d4")
          if(index == Arrays.length-1){
            Arrays=[]
          }
        })
        $(".right").css("background","#fff")
        $(".right").attr("background","#fff")
      }
      var dredgeOs = document.querySelectorAll(".dredgeOs")
       Array.from(dredgeOs).forEach(function(e,f){
        e.onclick=function(){
          var userIds = e.parentNode.getAttribute("userid")
          var userName = e.parentNode.childNodes[1].textContent
          var newN = $("<div class='dredgeOne' userId='"+userIds+"'><input type='checkbox' name='dredgeO' class='dredgeO' did='"+userIds+"'>"+userName+"</div>")
          $(newN).appendTo(".dredgeLC")
          e.parentNode.remove()
        }
       })
       document.querySelector(".dredgeQ").checked = false;
       pan = 0
    })
  }

  //删除右边并在左边创建员工
  function cancel(){
    // ArrOs = listArrs
    var dredgeOs = document.querySelectorAll(".dredgeOs")
        Array.from(dredgeOs).forEach(function(c,d){
          if(ArrOs.length == 0){
            var obj1={
              userid:c.parentNode.getAttribute("userid"),
              name:c.parentNode.childNodes[1].textContent
            }
            ArrOs.push(obj1)
          }else{
            var ks1 = true;
            ArrOs.forEach(function(e,f){
              if(e.userid == c.parentNode.getAttribute("userid")){
                ks1 = true;
              }else{
                ks1 = false;
              }
            })
            if(!ks1){
              objs={
                userid:c.parentNode.getAttribute("userid"),
                name:c.parentNode.childNodes[1].textContent
              }
              ArrOs.push(objs)
            }
          }
        })       
        console.log(ArrOs)
        var tableBott = document.querySelectorAll('.dredgeOnes');
        Array.from(tableBott).forEach(function(bom1,index){
            bom1.remove()
        })
        ArrOs.forEach(function(a,b){
          var newN = $("<div class='dredgeOne' userId='"+a.userid+"'><input type='checkbox' name='dredgeO' class='dredgeO' did='"+a.userid+"'>"+a.name+"</div>")
          $(newN).appendTo(".dredgeLC")
        })
        $(".left").css("background","#fff")
        $(".left").attr("background","#fff")
        document.querySelector(".dredgeS").checked = false;
        ArrOs=[]
  }
  //全部取消（左）
  $(".left").click(function(){
     cancel()
     quanx()
  })

  //全部取消（选中）
  $(".dredgeS").click(function(){
     cancel()
     quanx()
  })

   //全部取消（清空）
  $(".dredgeRB").click(function(){
     cancel()
     quanx()
  })
   //关闭
  $(".dredgeDel").click(function(){
    $(".dredge").css("display","none")
  })
  var title = $('#radarNews');//the element I want to monitor
  title.bind('DOMNodeInserted', function(e) {
      var dispenseSon = document.querySelector('.dispenseSons');
      var div_id = dispenseSon.getAttribute('sid');
      var div_name = dispenseSon.getAttribute('cid');
      $("#section").html(div_name)
      routAjax(div_id)
      // console.log(dispenseSon)

      // console.log(dispenseSon.getAttribute('sid'))
      // console.log(dispenseSon.getAttribute('cid'))

  });
  //确定批量开通
  $(".dredgeBtn").click(function(){
    var dredgeRC = document.querySelectorAll(".dredgeOnes");
    var onArr = []
    Array.from(dredgeRC).forEach(function(del,dindex){
      onArr.push(del.getAttribute("userid"))
    })
    if(onArr.length<1){
      alert("请选择需要开通的成员")
      return false
    }else{
      onAjax(onArr)
    }
    console.log(onArr)
  })
  //部门选择
  $(".choice").click(function(){
    // $(".tanz").css("display","block")
    var divs = "<div class='popup'><div class='popupTitle'>部门选择</div><div class='popupCenter'></div><div class='popupBottom'><div class='popupYes' onclick='radarOrganizations()'>确定</div></div><div class='padlock' onclick='padlocks()'><i class='iconfont icon-guanbi' id='del' style='line-height:30px;'></div></div>"
    $(divs).appendTo(window.parent.$("#messagediv"));
    window.parent.$("#messagedivs").css("display","block")
    firstAjax();
    // console.log(strss)
    // if(strss){
    //   $.each(strss, function(index, el) {
    //       console.log(index,el.name,el.d_id)
    //       var staAdd = $("<div class='stala stalap"+el.d_id+"' dids='"+el.d_id+"'><input type='radio' name='staffs' class='staffBott' dids='"+el.d_id+"' cis='"+el.name+"'></td><text>"+el.name+"</text></div>")
    //       $(staAdd).appendTo(window.parent.$(".popupCenter"));
    //       staffSelect(el.son,'stala'+el.d_id,"popupCenter")
    //       $("#section").html(el.name)
    //   })
    // }
    
  })
  var strss;

  // firstAjax();
  //第一次进入渲染部门
  function firstAjax(){
    $("#loads").css("display","block")
    $.ajax({
      url: window.minitest.url + "department/list",
      type:"GET",
      beforeSend: function (request) {
          request.setRequestHeader('token', window.base.getLocalStorage('token'));
      },
      success:function(res){
        // console.log(res)
        $("#loads").css("display","none")
        strss = res
          $.each(res, function(index, el) {
            // console.log(index,el.name,el.d_id)
            var staAdd = $("<div class='stala stalap"+el.d_id+"' dids='"+el.d_id+"'><input type='radio' name='staffs' class='staffBott' dids='"+el.d_id+"' cis='"+el.name+"'></td><text>"+el.name+"</text></div>")
            $(staAdd).appendTo(window.parent.$(".popupCenter"));
            staffSelect(el.son,'stala'+el.d_id,"popupCenter")
            $("#section").html(el.name)
        })
      },
      error:function(res){
        $("#loads").css("display","none")
        tokenDetection(res)
      }
    });
  }
  firstAjax2()
  //第一次进入渲染部门2
  function firstAjax2(){
    $.ajax({
      url: window.minitest.url + "department/list",
      type:"GET",
      beforeSend: function (request) {
          request.setRequestHeader('token', window.base.getLocalStorage('token'));
      },
      success:function(res){
        // console.log(res)
          $.each(res, function(index, el) {
            $("#section").html(el.name)
        })
      },
      error:function(res){
      }
    });
  }


  //选择部门页面一级渲染
  function staffSelect(staffSelects,cls,popupBottoms1){
    if(staffSelects){
     Array.from(staffSelects).forEach(function(staa,stab){
      var staAdd = $("<div class='stala stala"+staa.d_id+"' dids='"+staa.d_id+"' style='margin-left:10px'><input type='radio' name='staffs' class='staffBott' dids='"+staa.d_id+"' cis='"+staa.name+"'></td><text>"+staa.name+"</text></div>")
        $(staAdd).appendTo(window.parent.$("." + popupBottoms1));
        staffSelectse(staa.son,'stala'+staa.d_id,staa.d_id,popupBottoms1)
      
     })
    }
  }
  //选择部门页面二级渲染
  function staffSelectse(staffSelects,cls,index,popupBottoms2){
    if(staffSelects){
    var stalaz = 'stalaz' + index
    if($("."+cls).length ==1){
      var staAdd = $("<div class='"+stalaz+"' style='margin-left:10px'></div>")
          $(staAdd).appendTo(window.parent.$("." + popupBottoms2));
    }
     Array.from(staffSelects).forEach(function(staa,stab){
      var staAdd = $("<div class='stala ' dids='"+staa.d_id+"' style='margin-left:10px'><input type='radio' name='staffs' class='staffBott' dids='"+staa.d_id+"' cis='"+staa.name+"'></td><text>"+staa.name+"</text></div>")
        $(staAdd).appendTo("."+stalaz);
        staffSelectse(staa.son,'stala'+staa.d_id,staa.d_id)
      
     })
    }
  }
  //确定部门选择
  $(".tuanBtn").click(function(){
    // $(".tanz").css("display","none")
    var user_ids;
    var tr = document.querySelectorAll(".tr")
    Array.from(tr).forEach(function(c,d){
      c.remove()
    })
    var staffBott = document.querySelectorAll(".staffBott")
    Array.from(staffBott).forEach(function(a,b){
      if(a.checked == true){
        // console.log(a.parentNode.childNodes[1].textContent)
        // console.log(a.parentNode.getAttribute("dids"))
        $("#section").html(a.parentNode.childNodes[1].textContent)
        user_ids = a.parentNode.getAttribute("dids")
      }
    })
    routAjax(user_ids)
  })

   //点击部门查看成员请求接口
  function routAjax(routdid){
    $("#loads").css("display","block")
    $.ajax({
      url: window.minitest.url + "member/list/" + routdid,
      type:"GET",
      beforeSend: function (request) {
          request.setRequestHeader('token', window.base.getLocalStorage('token'));
      },
      success:function(res){
        $("#loads").css("display","none")
        //console.log(res)
        $("#sectionNum").html(res.length)
        var rasleng = Math.ceil(res.length / 10);
        fenye(rasleng)
        strAll(res,1)
        // staffAlls=res
      },
      error:function(res){
        $("#loads").css("display","none")
        tokenDetection(res)
      }
    });
  }
  //关闭部门选择框
  $(".tuanDel").click(function(){
    // $(".tanz").css("display","none")
  })
  //个人二维码
  function erwei(td8){
    Array.from(td8).forEach(function(a,b){
      a.onclick = function(){
        window.parent.$("#loads").css("display","block")
         // $(".erwz").css("display","block")
         var dids =a.getAttribute("did")
         console.log(dids)
         var divs = "<div class='popup'><div class='popupTitle'>"+a.parentNode.childNodes[1].innerHTML+"的二维码</div><div class='popupCenters'><div class='popupCentersImg'><img src='' class='radarImg'></div></div><div class='popupBottom'><div class='kongradar'></div><div class='popupYes2' did='"+dids+"' onclick='acquireAjax("+dids+")'>刷新</div></div><div class='padlock' onclick='padlocks()'><i class='iconfont icon-guanbi' id='del' style='line-height:30px;'></div></div>"
            $(divs).appendTo(window.parent.$("#messagediv"));
            window.parent.$("#messagedivs").css("display","block")
            
          $.ajax({
              url: window.minitest.url + "member/qrcode/" + dids,
              type:"GET",
              contentType: "application/json",
              dataType:"json",
              beforeSend: function (request) {
                  request.setRequestHeader('token', window.base.getLocalStorage('token'));
              },
              success:function(res){
                window.parent.$("#loads").css("display","none")
                // console.log(res)
                // console.log(res.url)
                if(res.error_code == 999){
                  alert("该成员未开通名片")
                }
                if(res.error_code == 0){
                  window.parent.$(".radarImg").attr("src",res.url)
                  // var divs = "<div class='popup'><div class='popupTitle'>"+a.parentNode.childNodes[1].innerHTML+"的二维码</div><div class='popupCenters'><div class='popupCentersImg'><img src='"+res.url+"' class='radarImg'></div></div><div class='popupBottom'><div class='kongradar'></div><div class='popupYes2' did='"+dids+"' onclick='acquireAjax("+dids+")'>刷新</div></div><div class='padlock' onclick='padlocks()'><i class='iconfont icon-guanbi' id='del' style='line-height:30px;'></div></div>"
                  // $(divs).appendTo(window.parent.$("#messagediv"));
                  // window.parent.$("#messagedivs").css("display","block")
                }
                if(res.error_code == 500){
                  alert("获取二维码失败，请刷新页面重试")
                }



                
              },
              error:function(res){
                window.parent.$("#loads").css("display","none")
                tokenDetection(res)
              }
          });
        
        // $(".erwTop").html(a.parentNode.childNodes[1].innerHTML+"的二维码")
        // console.log(a.parentNode.childNodes[1].innerHTML)
        // acquireAjax(a.getAttribute("did"))
      }
    })
  }
  $(".erwDel").click(function(){
    $(".erwz").css("display","none")
  })

  
</script>


</html>